package org.adream.account.controller;

import org.adream.account.aop.annotation.MonitorRequest;
import org.adream.account.entity.IntegralTypeEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.service.IntegralTypeService;
import org.adream.account.service.UserService;
import org.adream.account.util.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * 用户积分管理模块相关页面
 * 
 * @author sl
 *
 */
@Controller
public class UserIntegralController {

	private final static Logger logger = LoggerFactory.getLogger(UserIntegralController.class);

	@Autowired
	private UserService userService;
	
	@Autowired
	private IntegralTypeService integralTypeService;

	/**
	 * 用户积分
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "/userIntegralPage")
	@MonitorRequest
	public ModelAndView userIntegralPage(String uid) {
		ModelAndView mv = new ModelAndView("/userIntegral/userIntegral");
		return mv;
	}
	
	
	/**
	 * 用户积分更改
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "/userIntegralEditPage")
	@MonitorRequest
	public ModelAndView userIntegralEditPage(String uid) {
		ModelAndView mv = new ModelAndView("/userIntegral/user_integral_edit");
		ResultModel<?> resultModel = userService.queryUserIntergralByUidAndDr(uid, Constant.ONE);
		if(!ResultModel.SUCCESS.equals(resultModel.getReturnCode())) {
			logger.warn("查询用户积分数据失败:(");
			return null;
		}
		ResultModel<?> rlt = integralTypeService.queryIntegralTypes(Constant.ONE);
		if(!ResultModel.SUCCESS.equals(rlt.getReturnCode())) {
			logger.warn("查询积分类型数据失败:(");
			return null;
		}
		mv.getModel().put("integralTypes", rlt.getReturnObject());
		mv.getModel().put("userIntegral", resultModel.getReturnObject());
		return mv;
	}
	
	/**
	 * 	用户积分流水
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "/userIntegralLogPage")
	@MonitorRequest
	public ModelAndView userIntegralLogPage(String uid) {
		
		ModelAndView mv = new ModelAndView("/userIntegral/userIntegralLog");
		
		ResultModel<?> rlt = integralTypeService.queryIntegralTypes(Constant.ONE);
		if(ResultModel.SUCCESS.equals(rlt.getReturnCode())) {
			mv.addObject("typeList", rlt.getReturnObject());
		}
		return mv;
	}
}